package com.zian.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;


@Getter
public enum OrderStatusEnum {
    PENDING_PAYMENT(0, "待支付"),
    PAID(1, "已支付"),
    GOODS_ALLOCATED(2, "配货完成"),
    GOODS_DELIVERED(3, "出库成功"),
    TRANSACTION_SUCCESS(4, "交易成功"),
    MANUAL_CLOSED(-1, "手动关闭"),
    TIMEOUT_CLOSED(-2, "超时关闭"),
    MERCHANT_CLOSED(-3, "商家关闭");

    @JsonValue
    @EnumValue
    private final int code;
    private final String description;

    OrderStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    // 根据code值获取对应的枚举项
    public static OrderStatusEnum getByCode(int code) {
        for (OrderStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + code + "]");
    }
}
